# -- coding: utf-8 --

# 将原来支持的json_dumps_params参数固定写死成{'ensure_ascii':False}
import json
from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpResponse


class JsonResponseCn(HttpResponse):
    """
    忽略注释部分内容
    """
    def __init__(self, data, encoder=DjangoJSONEncoder, safe=True, **kwargs):
        if safe and not isinstance(data, dict):
            raise TypeError(
                'In order to allow non-dict objects to be serialized set the '
                'safe parameter to False.'
            )
        kwargs.setdefault('content_type', 'application/json')
        data = json.dumps(data, cls=encoder, **{'ensure_ascii':False})
        super().__init__(content=data, **kwargs)

    def hello_json(request, *args, **kwargs):
        data = {'code': 0, "content": "返回中文字符串", "err_msg": ""}
        return JsonResponseCn(data)